/**
 * Copyright 2014-2020  the original author or authors.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.upb.webserver.common.properties;

import com.upb.webserver.common.enums.ChainTypeEnum;
import lombok.Data;
import lombok.extern.log4j.Log4j2;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * constants.
 */
@Log4j2
@Data
@Component
@ConfigurationProperties(prefix = "upb.webserver")
public class WebServerProperties {

    public static final String COOKIE_JSESSIONID = "JSESSIONID"; // cookie key---session
    public static final String HAS_ROLE_ADMIN = "hasRole('admin')";

    //receive http request
    private String permitUrlArray;
    private Integer verificationCodeMaxAge = 300; // seconds
    private Integer authTokenMaxAge = 900; // seconds
    private Boolean enableLoginVerification = true;
    private Integer httpTimeOut = 30 * 000;//ms
    private String sshPrivateKey = System.getProperty("user.home") + File.separator + ".ssh" + File.separator + "id_rsa";
    private String appMarketBasePath;
    private Integer appMarketDocumentDirectorySizeMax=4;//应用市场文档目录大小最大值
    private Integer appMarketContractDirectorySizeMax=4;//应用市场合约目录大小最大值
    private Integer appMarketRemarkFileSizeMax=4;//应用市场备注文件大小最大值
    private Integer  appMarketLogoSizeMax=1;//应用市场logo大小最大值
    private Boolean openDebug = false;

    //switch
    private Boolean supportFiscoBcos = true;//true:support fisco bcos  false: not support fisco bcos
    private Boolean supportHyperledger = true;  //true:support hyperledger  false: not support hyperledger
    private List<Byte> supportChainTypeList = new ArrayList<>(); //support chainType list


    @EventListener(ApplicationReadyEvent.class)
    public void init() {
        if (supportFiscoBcos) {
            supportChainTypeList.add(ChainTypeEnum.FISCO.getId());
        }
        if (supportHyperledger) {
            supportChainTypeList.add(ChainTypeEnum.FABRIC.getId());
        }
    }

}